core: Unify object deletion code with prune
authorColin Walters <walters@verbum.org>
Sun, 20 Jul 2014 12:35:58 +0000 (08:35 -0400)
committerColin Walters <walters@verbum.org>
Sun, 20 Jul 2014 12:57:37 +0000 (08:57 -0400)
The prune API duplicated logic to delete objects, and furthermore the
core API to delete an object didn't clean up detached metadata.

Fix the duplication by doing the obvious thing: prune should call
_delete.

https://bugzilla.gnome.org/show_bug.cgi?id=733452

src/libostree/ostree-repo-prune.c
src/libostree/ostree-repo.c

index 6479aa21bd042af73fdc98eca4cb93d86d482bd8..ac5364ac9d5c23acd4e04830c89fdbdd0439e2b7 100644 (file)
@@ -45,36 +45,24 @@ maybe_prune_loose_object (OtPruneData        *data,
 {
   gboolean ret = FALSE;
   gs_unref_variant GVariant *key = NULL;
-  gs_unref_object GFile *objf = NULL;
 
   key = ostree_object_name_serialize (checksum, objtype);
 
-  objf = _ostree_repo_get_object_path (data->repo, checksum, objtype);
-
   if (!g_hash_table_lookup_extended (data->reachable, key, NULL, NULL))
     {
       if (!(flags & OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE))
         {
-          gs_unref_object GFileInfo *info = NULL;
+          guint64 storage_size = 0;
+
+          if (!ostree_repo_query_object_storage_size (data->repo, objtype, checksum,
+                                                      &storage_size, cancellable, error))
+            goto out;
 
-          if (!ot_gfile_query_info_allow_noent (objf, OSTREE_GIO_FAST_QUERYINFO,
-                                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                                &info, cancellable, error))
+          if (!ostree_repo_delete_object (data->repo, objtype, checksum,
+                                          cancellable, error))
             goto out;
 
-          if (info)
-            {
-              if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
-                {
-                  gs_unref_object GFile *detached_metadata =
-                    _ostree_repo_get_commit_metadata_loose_path (data->repo, checksum);
-                  if (!ot_gfile_ensure_unlinked (detached_metadata, cancellable, error))
-                    goto out;
-                }
-              if (!gs_file_unlink (objf, cancellable, error))
-                goto out;
-              data->freed_bytes += g_file_info_get_size (info);
-            }
+          data->freed_bytes += storage_size;
         }
       if (OSTREE_OBJECT_TYPE_IS_META (objtype))
         data->n_unreachable_meta++;
index 70e1e9a96564fbaa1da54727f4e8156064b236dc..583d685bb38f27c36e7eb86ca5874cf8cee2046a 100644 (file)
@@ -1598,8 +1598,24 @@ ostree_repo_delete_object (OstreeRepo           *self,
                            GCancellable         *cancellable,
                            GError              **error)
 {
-  gs_unref_object GFile *objpath = _ostree_repo_get_object_path (self, sha256, objtype);
-  return gs_file_unlink (objpath, cancellable, error);
+  gboolean ret = FALSE;
+  gs_unref_object GFile *objpath = NULL;
+
+  if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
+    {
+      gs_unref_object GFile *detached_metadata =
+        _ostree_repo_get_commit_metadata_loose_path (self, sha256);
+      if (!ot_gfile_ensure_unlinked (detached_metadata, cancellable, error))
+        goto out;
+    }
+
+  objpath = _ostree_repo_get_object_path (self, sha256, objtype);
+  if (!gs_file_unlink (objpath, cancellable, error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  return ret;
 }
 
 /**